/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using System.Collections.Generic;
using NetProtocol.POD;
using NetProtocol.Enum;
using IQIGame.Onigao.Game;
using IQIGame.Onigao.GamePlay;
using IQIGame.Onigao.Framework;
using System.Threading.Tasks;
using System;

namespace NetProtocol.Server {
	/// <summary>
	/// 宠物模块
	/// module : pet
	/// </summary>
	public interface SNetPet : INetServerModule {
		Dictionary<int, MessageHandler> INetServerModule.GetModuleFunction()
        {	
            return new()
            {
                { NetMessageId.pet_free, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.pet_free, "Recv->" + data.ToString());
#endif
		                FreeRequest _data = (FreeRequest)data;
						return CS_free(session, _data.id);
		            } 
            	},
                { NetMessageId.pet_upLevel, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.pet_upLevel, "Recv->" + data.ToString());
#endif
		                UpLevelRequest _data = (UpLevelRequest)data;
						return CS_upLevel(session, _data.id, _data.itemCount);
		            } 
            	},
                { NetMessageId.pet_rename, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.pet_rename, "Recv->" + data.ToString());
#endif
		                RenameRequest _data = (RenameRequest)data;
						return CS_rename(session, _data.id, _data.newName);
		            } 
            	},
                { NetMessageId.pet_lock, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.pet_lock, "Recv->" + data.ToString());
#endif
		                LockRequest _data = (LockRequest)data;
						return CS_lock(session, _data.id, _data.isLock);
		            } 
            	},
                { NetMessageId.pet_unlockSkillSlot, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.pet_unlockSkillSlot, "Recv->" + data.ToString());
#endif
		                UnlockSkillSlotRequest _data = (UnlockSkillSlotRequest)data;
						return CS_unlockSkillSlot(session, _data.id);
		            } 
            	},
                { NetMessageId.pet_putOnRandAttr, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.pet_putOnRandAttr, "Recv->" + data.ToString());
#endif
		                PutOnRandAttrRequest _data = (PutOnRandAttrRequest)data;
						return CS_putOnRandAttr(session, _data.id, _data.groupId, _data.randAttrId);
		            } 
            	},
                { NetMessageId.pet_putOffRandAttr, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.pet_putOffRandAttr, "Recv->" + data.ToString());
#endif
		                PutOffRandAttrRequest _data = (PutOffRandAttrRequest)data;
						return CS_putOffRandAttr(session, _data.id, _data.groupId, _data.randAttrId);
		            } 
            	},
            };
        }
        
        Dictionary<int, Func<IReceiveMessage>> INetServerModule.GetModuleRequest() 
        {
	        return new ()
	        {
	        	{NetMessageId.pet_free, ()=> new FreeRequest()},
	        	{NetMessageId.pet_upLevel, ()=> new UpLevelRequest()},
	        	{NetMessageId.pet_rename, ()=> new RenameRequest()},
	        	{NetMessageId.pet_lock, ()=> new LockRequest()},
	        	{NetMessageId.pet_unlockSkillSlot, ()=> new UnlockSkillSlotRequest()},
	        	{NetMessageId.pet_putOnRandAttr, ()=> new PutOnRandAttrRequest()},
	        	{NetMessageId.pet_putOffRandAttr, ()=> new PutOffRandAttrRequest()},
	        };
	    }
        
#region Server-side Interface
		/// <summary>
        ///  放生
        /// </summary>
	    protected FreeResult CS_free(ISession session, long id);
		/// <summary>
        ///  升级 -- 参数为材料数
        /// </summary>
	    protected UpLevelResult CS_upLevel(ISession session, long id, int itemCount);
		/// <summary>
        ///  重命名
        /// </summary>
	    protected RenameResult CS_rename(ISession session, long id, string newName);
		/// <summary>
        ///  锁定
        /// </summary>
	    protected LockResult CS_lock(ISession session, long id, bool isLock);
		/// <summary>
        ///  解锁技能槽
        /// </summary>
	    protected UnlockSkillSlotResult CS_unlockSkillSlot(ISession session, long id);
		/// <summary>
        ///  使用词条--不同组可能有重复
        /// </summary>
	    protected PutOnRandAttrResult CS_putOnRandAttr(ISession session, long id, int groupId, int randAttrId);
		/// <summary>
        ///  取下词条
        /// </summary>
	    protected PutOffRandAttrResult CS_putOffRandAttr(ISession session, long id, int groupId, int randAttrId);
#endregion
#region Client-side Interface
		/// <summary>
        ///  放生结果，从本地移除			
        /// </summary>
        public FreeResult SC_freeResult(Task<FreeResult> future){return new FreeResult(future);}
        public FreeResult SC_freeResult(int code){return new FreeResult(code);}
		/// <summary>
        ///  升级结果，成功时替换
        /// </summary>
        public UpLevelResult SC_upLevelResult(Task<UpLevelResult> future){return new UpLevelResult(future);}
        public UpLevelResult SC_upLevelResult(int code, PetPOD petPOD){return new UpLevelResult(code, petPOD);}
        public UpLevelResult SC_upLevelResult(int code){return new UpLevelResult(code);}
		/// <summary>
        ///  重命名结果，自行替换名字
        /// </summary>
        public RenameResult SC_renameResult(Task<RenameResult> future){return new RenameResult(future);}
        public RenameResult SC_renameResult(int code){return new RenameResult(code);}
		/// <summary>
        ///  锁定结果
        /// </summary>
        public LockResult SC_lockResult(Task<LockResult> future){return new LockResult(future);}
        public LockResult SC_lockResult(int code){return new LockResult(code);}
		/// <summary>
        ///  解锁技能槽
        /// </summary>
        public UnlockSkillSlotResult SC_unlockSkillSlotResult(Task<UnlockSkillSlotResult> future){return new UnlockSkillSlotResult(future);}
        public UnlockSkillSlotResult SC_unlockSkillSlotResult(int code){return new UnlockSkillSlotResult(code);}
		/// <summary>
        ///  使用词条效果
        /// </summary>
        public PutOnRandAttrResult SC_putOnRandAttrResult(Task<PutOnRandAttrResult> future){return new PutOnRandAttrResult(future);}
        public PutOnRandAttrResult SC_putOnRandAttrResult(int code, PetPOD petPOD){return new PutOnRandAttrResult(code, petPOD);}
        public PutOnRandAttrResult SC_putOnRandAttrResult(int code){return new PutOnRandAttrResult(code);}
		/// <summary>
        ///  取下词条效果
        /// </summary>
        public PutOffRandAttrResult SC_putOffRandAttrResult(Task<PutOffRandAttrResult> future){return new PutOffRandAttrResult(future);}
        public PutOffRandAttrResult SC_putOffRandAttrResult(int code, PetPOD petPOD){return new PutOffRandAttrResult(code, petPOD);}
        public PutOffRandAttrResult SC_putOffRandAttrResult(int code){return new PutOffRandAttrResult(code);}
		/// <summary>
        ///  通知激活了宠物
        /// </summary>
		public bool SC_notifyPetActive(ISession session, PetPOD petPOD){
	        return NetProtocolHelper.SendMessage(session, new NotifyPetActive(petPOD));
	    }
	    public void SC_notifyPetActive_Broadcast(List<ISession> sessions, PetPOD petPOD){
	        NetProtocolHelper.BroadcastMessage(sessions, new NotifyPetActive(petPOD));
	    }
		/// <summary>
        ///  通知宠物背包容量变化
        /// </summary>
		public bool SC_notifyPetBagCapacity(ISession session, int capacity){
	        return NetProtocolHelper.SendMessage(session, new NotifyPetBagCapacity(capacity));
	    }
	    public void SC_notifyPetBagCapacity_Broadcast(List<ISession> sessions, int capacity){
	        NetProtocolHelper.BroadcastMessage(sessions, new NotifyPetBagCapacity(capacity));
	    }
		/// <summary>
        ///  通知删除了宠物--主要用于gm
        /// </summary>
		public bool SC_notifyPetRemove(ISession session, List<long> removeList){
	        return NetProtocolHelper.SendMessage(session, new NotifyPetRemove(removeList));
	    }
	    public void SC_notifyPetRemove_Broadcast(List<ISession> sessions, List<long> removeList){
	        NetProtocolHelper.BroadcastMessage(sessions, new NotifyPetRemove(removeList));
	    }
#endregion

#region Messages
	public class FreeResult : MessageResult {
	    public FreeResult(Task<FreeResult> future): base(future) { }
		public FreeResult(int code): base(code) { }
		public new FreeResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
        public override MessageResult GetFutureResult(Task task) { return ((Task<FreeResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.pet_freeResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.pet_freeResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			return si_p;
		}
		public override string ToString() {
    		return "Pet.SC_freeResult { "
			+ "code="
			+ code
			+" }";
		}
	}
	public class UpLevelResult : MessageResult {
	    private PetPOD petPOD;
	    public UpLevelResult(Task<UpLevelResult> future): base(future) { }
		public UpLevelResult(int code): base(code) { }
		public new UpLevelResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
	    internal UpLevelResult(int code, PetPOD petPOD){
	        this.code = code;
	        this.petPOD = petPOD;
	    }
        public override MessageResult GetFutureResult(Task task) { return ((Task<UpLevelResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.pet_upLevelResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.pet_upLevelResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			_out.Write_pod(petPOD);
			return si_p;
		}
		public override string ToString() {
    		return "Pet.SC_upLevelResult { "
			+ "code="
			+ code
			+ ", petPOD="
			+ petPOD
			+" }";
		}
	}
	public class RenameResult : MessageResult {
	    public RenameResult(Task<RenameResult> future): base(future) { }
		public RenameResult(int code): base(code) { }
		public new RenameResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
        public override MessageResult GetFutureResult(Task task) { return ((Task<RenameResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.pet_renameResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.pet_renameResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			return si_p;
		}
		public override string ToString() {
    		return "Pet.SC_renameResult { "
			+ "code="
			+ code
			+" }";
		}
	}
	public class LockResult : MessageResult {
	    public LockResult(Task<LockResult> future): base(future) { }
		public LockResult(int code): base(code) { }
		public new LockResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
        public override MessageResult GetFutureResult(Task task) { return ((Task<LockResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.pet_lockResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.pet_lockResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			return si_p;
		}
		public override string ToString() {
    		return "Pet.SC_lockResult { "
			+ "code="
			+ code
			+" }";
		}
	}
	public class UnlockSkillSlotResult : MessageResult {
	    public UnlockSkillSlotResult(Task<UnlockSkillSlotResult> future): base(future) { }
		public UnlockSkillSlotResult(int code): base(code) { }
		public new UnlockSkillSlotResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
        public override MessageResult GetFutureResult(Task task) { return ((Task<UnlockSkillSlotResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.pet_unlockSkillSlotResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.pet_unlockSkillSlotResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			return si_p;
		}
		public override string ToString() {
    		return "Pet.SC_unlockSkillSlotResult { "
			+ "code="
			+ code
			+" }";
		}
	}
	public class PutOnRandAttrResult : MessageResult {
	    private PetPOD petPOD;
	    public PutOnRandAttrResult(Task<PutOnRandAttrResult> future): base(future) { }
		public PutOnRandAttrResult(int code): base(code) { }
		public new PutOnRandAttrResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
	    internal PutOnRandAttrResult(int code, PetPOD petPOD){
	        this.code = code;
	        this.petPOD = petPOD;
	    }
        public override MessageResult GetFutureResult(Task task) { return ((Task<PutOnRandAttrResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.pet_putOnRandAttrResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.pet_putOnRandAttrResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			_out.Write_pod(petPOD);
			return si_p;
		}
		public override string ToString() {
    		return "Pet.SC_putOnRandAttrResult { "
			+ "code="
			+ code
			+ ", petPOD="
			+ petPOD
			+" }";
		}
	}
	public class PutOffRandAttrResult : MessageResult {
	    private PetPOD petPOD;
	    public PutOffRandAttrResult(Task<PutOffRandAttrResult> future): base(future) { }
		public PutOffRandAttrResult(int code): base(code) { }
		public new PutOffRandAttrResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
	    internal PutOffRandAttrResult(int code, PetPOD petPOD){
	        this.code = code;
	        this.petPOD = petPOD;
	    }
        public override MessageResult GetFutureResult(Task task) { return ((Task<PutOffRandAttrResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.pet_putOffRandAttrResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.pet_putOffRandAttrResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			_out.Write_pod(petPOD);
			return si_p;
		}
		public override string ToString() {
    		return "Pet.SC_putOffRandAttrResult { "
			+ "code="
			+ code
			+ ", petPOD="
			+ petPOD
			+" }";
		}
	}
	public class NotifyPetActive : MessageNotify {
		private PetPOD petPOD;
		public NotifyPetActive(PetPOD petPOD) {
		    this.petPOD = petPOD;
		}
		public override int GetMessageId() {return NetMessageId.pet_notifyPetActive;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.pet_notifyPetActive;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_pod(petPOD);
			return si_p;
		}
		public override string ToString() {
			return "Pet.SC_notifyPetActive { "
			+ "petPOD="
			+ petPOD
			+" }";
		}
	}
	public class NotifyPetBagCapacity : MessageNotify {
		private int capacity;
		public NotifyPetBagCapacity(int capacity) {
		    this.capacity = capacity;
		}
		public override int GetMessageId() {return NetMessageId.pet_notifyPetBagCapacity;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.pet_notifyPetBagCapacity;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(capacity);
			return si_p;
		}
		public override string ToString() {
			return "Pet.SC_notifyPetBagCapacity { "
			+ "capacity="
			+ capacity
			+" }";
		}
	}
	public class NotifyPetRemove : MessageNotify {
		private List<long> removeList;
		public NotifyPetRemove(List<long> removeList) {
		    this.removeList = removeList == null ? null : new (removeList);
		}
		public override int GetMessageId() {return NetMessageId.pet_notifyPetRemove;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.pet_notifyPetRemove;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_list_long(removeList);	
			return si_p;
		}
		public override string ToString() {
			return "Pet.SC_notifyPetRemove { "
			+ "removeList="
			+ removeList.ToString<long>()
			+" }";
		}
	}
	private class FreeRequest : IReceiveMessage
    {
		internal long id;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            id = _in.HasRemaining() ? _in.Read_long() : default;
		}
        public int GetMessageId() { return NetMessageId.pet_free; }
        public override string ToString()
        {
            return "Pet.free"+ ", id="+ id;
        }
    }
	private class UpLevelRequest : IReceiveMessage
    {
		internal long id;
		internal int itemCount;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            id = _in.HasRemaining() ? _in.Read_long() : default;
            itemCount = _in.HasRemaining() ? _in.Read_int() : default;
		}
        public int GetMessageId() { return NetMessageId.pet_upLevel; }
        public override string ToString()
        {
            return "Pet.upLevel"+ ", id="+ id+ ", itemCount="+ itemCount;
        }
    }
	private class RenameRequest : IReceiveMessage
    {
		internal long id;
		internal string newName;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            id = _in.HasRemaining() ? _in.Read_long() : default;
            newName = _in.HasRemaining() ? _in.Read_string() : default;
		}
        public int GetMessageId() { return NetMessageId.pet_rename; }
        public override string ToString()
        {
            return "Pet.rename"+ ", id="+ id+ ", newName="+ newName;
        }
    }
	private class LockRequest : IReceiveMessage
    {
		internal long id;
		internal bool isLock;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            id = _in.HasRemaining() ? _in.Read_long() : default;
            isLock = _in.HasRemaining() ? _in.Read_boolean() : default;
		}
        public int GetMessageId() { return NetMessageId.pet_lock; }
        public override string ToString()
        {
            return "Pet.lock"+ ", id="+ id+ ", isLock="+ isLock;
        }
    }
	private class UnlockSkillSlotRequest : IReceiveMessage
    {
		internal long id;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            id = _in.HasRemaining() ? _in.Read_long() : default;
		}
        public int GetMessageId() { return NetMessageId.pet_unlockSkillSlot; }
        public override string ToString()
        {
            return "Pet.unlockSkillSlot"+ ", id="+ id;
        }
    }
	private class PutOnRandAttrRequest : IReceiveMessage
    {
		internal long id;
		internal int groupId;
		internal int randAttrId;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            id = _in.HasRemaining() ? _in.Read_long() : default;
            groupId = _in.HasRemaining() ? _in.Read_int() : default;
            randAttrId = _in.HasRemaining() ? _in.Read_int() : default;
		}
        public int GetMessageId() { return NetMessageId.pet_putOnRandAttr; }
        public override string ToString()
        {
            return "Pet.putOnRandAttr"+ ", id="+ id+ ", groupId="+ groupId+ ", randAttrId="+ randAttrId;
        }
    }
	private class PutOffRandAttrRequest : IReceiveMessage
    {
		internal long id;
		internal int groupId;
		internal int randAttrId;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            id = _in.HasRemaining() ? _in.Read_long() : default;
            groupId = _in.HasRemaining() ? _in.Read_int() : default;
            randAttrId = _in.HasRemaining() ? _in.Read_int() : default;
		}
        public int GetMessageId() { return NetMessageId.pet_putOffRandAttr; }
        public override string ToString()
        {
            return "Pet.putOffRandAttr"+ ", id="+ id+ ", groupId="+ groupId+ ", randAttrId="+ randAttrId;
        }
    }
	}
#endregion
}